<div class="row clearfix" [@routerTransition]>
    <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
        <div class="card main-content">
            <div class="header">
                <h2>
                    {{l('Persons')}}
                </h2>
                <ul class="header-dropdown m-r--5">
                    <i class="fa fa-spin fa-spinner" *ngIf="isTableLoading"></i>
                    <li class="dropdown">
                        <a href="javascript:void(0);" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
                            <i class="material-icons">more_vert</i>
                        </a>
                        <ul class="dropdown-menu pull-right">
                            <li>
                                <a href="javascript:void(0);" class=" waves-effect <waves-block></waves-block>" (click)="refresh();">
                                    <i class="material-icons">refresh</i> Refresh</a>
                            </li>
                        </ul>
                    </li>
                </ul>
                <div class="row clearfix" style="margin-top: 10px;">
                    <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
                        <div class="input-group btn-group btn-primary form-group">
                            <input [(ngModel)]="filter" name="filterText" (keypress)="keyPress($event)" auto-focus class="form-control" [placeholder]="l('SearchWithThreeDot')"
                                type="text">
                            <span class="input-group-btn">
                                <button (click)="refresh()" class="btn btn-default" type="submit">
                                    <i class="icon-magnifier"></i>
                                </button>
                            </span>
                        </div>
                    </div>
                </div>
            </div>
            <div class="body table-responsive">
                <table class="table table-hover table-striped">
                    <thead>
                        <tr>
                            <th>{{l('Name')}}</th>
                            <th>{{l('Email')}}</th>
                            <th>{{l('Address')}}</th>
                            <th>{{l('PhoneNumber')}}</th>
                            <th>{{l('Actions')}}</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr *ngFor="let person of persons | paginate: { id: 'server', itemsPerPage: pageSize, currentPage: pageNumber, totalItems: totalItems }">
                            <td>{{person.name}}</td>
                            <td>{{person.email}}</td>
                            <td>{{person.address}}</td>
                            <td>
                                <span style="margin: 2px;" *ngFor="let phone of person.phoneNumbers;index as i">
                                    {{l(phone.typeDescription)}}-{{phone.number}}
                                    <input type="button" value="删" class="btn btn-danger btn-sm" (click)="deletePhoneNumber(phone.id, phone.number)">
                                    <span *ngIf="person.phoneNumbers.length-1 > i" style="margin-left: 10px;">/</span>
                                </span>
                            </td>
                            <td class="dropdown">
                                <a href="javascript:void(0);" class="dropdown-toggle" data-toggle="dropdown" person="button" aria-haspopup="true" aria-expanded="false">
                                    <i class="material-icons">menu</i>
                                </a>
                                <ul class="dropdown-menu pull-right">
                                    <li>
                                        <a href="javascript:void(0);" class="waves-effect waves-block" (click)="editPerson(person)">
                                            <i class="material-icons">create</i>{{l("Edit")}}</a>
                                    </li>
                                    <li>
                                        <a href="javascript:void(0);" class="waves-effect waves-block" (click)="addPhoneNumber(person)">
                                            <i class="material-icons">people</i>{{l("AddPhoneNumber")}}</a>
                                    </li>
                                    <li>
                                        <a href="javascript:void(0);" class="waves-effect waves-block" (click)="delete(person)">
                                            <i class="material-icons">delete_sweep</i>{{l("Delete")}}</a>
                                    </li>
                                </ul>
                            </td>
                        </tr>
                    </tbody>
                </table>

                <div class="text-align: center;" *ngIf="totalItems > pageSize">
                    <pagination-controls (pageChange)="getDataPage($event)" id="server"></pagination-controls>
                </div>
                <button type="button" data-toggle="modal" class="btn btn-primary btn-circle waves-effect waves-circle waves-float pull-right"
                    (click)="createPerson()">
                    <i class="material-icons">add</i>
                </button>
            </div>
        </div>
    </div>
</div>

<app-create-person #createPersonModal (modalSave)="refresh()"></app-create-person>
<app-edit-person #editPersonModal (modalSave)="refresh()"></app-edit-person>
<app-phone-number #phoneNumberModal (modalSave)="refresh()"></app-phone-number>
